package com.lnt.mq.rabbitmq.workqueue;

import com.google.gson.Gson;
import com.lnt.mq.rabbitmq.util.RabbitConstant;
import com.lnt.mq.rabbitmq.util.RabbitUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 订单系统
 * 扮演一个发送者的身份
 */
public class OrderSystem {

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(RabbitConstant.QUEUR_SMS, false, false, false, null);
        for (int i = 0; i < 100; i++) {
            SMS sms = new SMS("乘客" + i, "132000000" + i, "您的车票已订购成功");
            String jsonString = new Gson().toJson(sms);
            channel.basicPublish("", RabbitConstant.QUEUR_SMS, null, jsonString.getBytes());
        }
        System.out.println("数据发送成功");
        channel.close();
        connection.close();
    }
}

